package com.thx.appserver.dao;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import com.thx.appserver.model.CappNews;
import com.thx.common.orm.PaginationDao;
import com.thx.common.util.StringUtil;


@Repository
public class CappNewsDao extends PaginationDao<CappNews> {

	@SuppressWarnings("unchecked")
	public List<CappNews> queryAll(CappNews entity, int start, int limit) {
		StringBuffer hqlBuffer = new StringBuffer("from CappNews where 1=1 ");
		if (null!=entity && null!=entity.getTitle() && !entity.getTitle().equals("")) {
			hqlBuffer.append(" and title like '%"+entity.getTitle()+"%'");
		}
		hqlBuffer.append("order by newsId desc");
		return createQuery(hqlBuffer.toString()).list();

	}

	public int countAll(CappNews entity) {
		String hql = "select count(*) from CappNews where 1=1";
		if (null!=entity && StringUtils.isNotBlank(entity.getTitle())) {
			hql +=" and title like '%"+entity.getTitle()+"%'";
		}
		Long count = (Long) createQuery(hql).uniqueResult();
		return new Integer(count + "");
	}
	public List<CappNews> searchNew(CappNews entity) {
		StringBuffer hqlBuffer = new StringBuffer("from CappNews where 1=1 ");
		if (null!=entity && StringUtils.isNotBlank(entity.getTitle())) {
			hqlBuffer.append(" and title like '%"+entity.getTitle()+"%'");
		}
		hqlBuffer.append("order by newsId desc");
		return findPageList(hqlBuffer.toString());
	}
  
}
